package diamondRingService.impl;

import diamondRingDao.impl.AdminDaoImpl;
import diamondRingEntity.Admin;
import diamondRingEntity.DiamondRingEntity;
import diamondRingService.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    AdminDaoImpl adm = new AdminDaoImpl();

    /*
    后台登录
     */
    @Override
    public int Login(Admin admin) {
        int count=0;
        try {
            if (null != admin){
                //把数据送到数据访问层
                count=adm.Login(admin);
            }else {
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层"+e);
        }
        return count;
    }

    /*
    后台修改密码
     */
    @Override
    public int UpdatePassword(Admin admin) {
        int count=0;
        try {
            if (null != admin){
                //把数据送到数据访问层
                count=adm.UpdatePassword(admin);
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层"+e);
        }
        return count;
    }

    /*
    用户查询
     */
    @Override
    public List<Admin> SelectAdmin() {
        List<Admin> list = null;
        list = adm.SelectAdmin();
        return list;
    }

    /*
    按用户名查询用户
    */
    @Override
    public List<Admin> SelectNameAdmin(String adminName) {
        List<Admin> list = null;
        list = adm.SelectNameAdmin(adminName);
        return list;
    }

    /*
    按用户ID删除用户
     */
    @Override
    public int DeleteIdAdmin(String ID) {
        int count=0;
        try {
            if (null != ID){
                //把数据送到数据访问层
                count=adm.DeleteIdAdmin(ID);
            }else{
                count=-1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层"+e);
        }
        return count;
    }

    /*
    查看用户信息
     */
    @Override
    public List<Admin> SelectAdminInfoAdmin(String ID) {
        List<Admin> list = null;
        list = adm.SelectAdminInfoAdmin(ID);
        return list;
    }

    /*
   按用户ID修改用户信息
    */
    @Override
    public int UpdateAdminInfo(Admin admin,String id) {
        int count=0;
        try {
            if (null != admin){
                //把数据送到数据访问层
                count=adm.UpdateAdminInfo(admin,id);
            }else{
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层"+e);
        }
        return count;
    }

    /*
    添加用户
     */
    @Override
    public int InsertAdminInfo(Admin admin) {
        int count=0;
        try {
            if (null != admin){
                //把数据送到数据访问层
                count=adm.InsertAdminInfo(admin);
            }else{
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层"+e);
        }
        return count;
    }

    /*
    商品查询
     */
    @Override
    public List<DiamondRingEntity> getAll() {
        List<DiamondRingEntity>list=adm.getAll();
        return list;
    }

    /*
   按钻戒ID查看钻戒信息
   */
    @Override
    public List<DiamondRingEntity> LookDRinfo(int ID) {
        List<DiamondRingEntity> list = null;
        list = adm.LookDRinfo(ID);
        return list;
    }

    /*
    商品模糊查询
     */
    @Override
    public List<DiamondRingEntity> vaugeFind(String vauge) {
        List<DiamondRingEntity>list=null;
        list=adm.vaugeFind(vauge);
        return list;
    }

    /*
    按商品ID修改商品信息
     */
    @Override
    public int UpdateGoodsInfo(DiamondRingEntity diamondRingEntity, int id) {
        int count=0;
        try {
            if (null != diamondRingEntity){
                //把数据送到数据访问层
                count=adm.UpdateGoodsInfo(diamondRingEntity,id);
            }else{
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层"+e);
        }
        return count;
    }

     /*
    按商品ID下架商品
     */
    @Override
    public int UpdateGoods(int id) {
        int count = 0;
        try {
            if (id>0) {
                //把数据送到数据访问层
                count = adm.DelGoods(id);
            } else {
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层" + e);
        }
        return count;
    }

    /*
 按商品ID上架商品
  */
    @Override
    public int AddGoods(int id) {
        int count = 0;
        try {
            if (id>0) {
                //把数据送到数据访问层
                count = adm.AddGoods(id);
            } else {
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层" + e);
        }
        return count;
    }

    /*
    新增商品
     */
    @Override
    public int Insert(DiamondRingEntity diamondRingEntity) {
        int count = 0;
        try {
            if (diamondRingEntity != null) {
                //把数据送到数据访问层
                count = adm.Insert(diamondRingEntity);
            } else {
                count = -1;
            }
        } catch (Exception e) {
            System.err.println("业务逻辑层" + e);
        }
        return count;
    }
}
